package dao;

import java.util.ArrayList;
import java.util.List;

import model.Aposta;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import dataBase.GerarTabelas;

public class ApostaDao {

	public static void adicionarTarefa(Aposta aposta) {

		Session session = GerarTabelas.preparaSessao();
		session.save(aposta);
		session.beginTransaction().commit();
		session.close();
	}

	public static List<Aposta> retornarTodasAsApostasPorUsuario(long id_usuario) {

		Session session = GerarTabelas.preparaSessao();

		Criteria criteria = session.createCriteria(Aposta.class);
		criteria.add(Restrictions.eq("id_usuario", id_usuario));
		List<Aposta> apostas = new ArrayList<>();
		apostas = criteria.list();

		return apostas;
	}

	public static void deletarTarefa(Aposta aposta) {
		Session session = GerarTabelas.preparaSessao();
		Transaction transaction = session.beginTransaction();
		Aposta apostaBd = (Aposta) session.load(Aposta.class, aposta.getId());
		session.delete(apostaBd);
		transaction.commit();
		session.close();

	}

	public static void modificarAposta(Aposta aposta) {
		Session session = GerarTabelas.preparaSessao();
		Transaction transaction = session.beginTransaction();
		Aposta apostaBd = (Aposta) session.load(Aposta.class, aposta.getId());
		apostaBd = aposta;
		session.update(apostaBd);
		transaction.commit();
		session.close();

	}
}
